﻿
using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class yinpin_lujing : Form
    {
        public yinpin_lujing()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            FolderBrowserDialog folder = new FolderBrowserDialog();
            DialogResult result = folder.ShowDialog();
            
            string[] files = Directory.GetFiles(this.textBox1.Text);
            foreach (var file in files)
            {
                
                string fileName = file.Substring(file.LastIndexOf("\\") + 1);
                
                File.Copy(file, folder.SelectedPath + "\\" + fileName);
            }
            this.textBox2.Text = folder.SelectedPath;
            this.textBox2.ReadOnly = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DBHelper db = new DBHelper();

            db.OpenConnection();
            string sql = "update resource_path set resource_path=N'" + this.textBox2.Text + "' where resource_id=3";
            SqlCommand comm = new SqlCommand(sql, db.Connection);
            int count = comm.ExecuteNonQuery();
            if (count > 0)
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("失败");
                this.Close();
            }
            db.CloseConnection();
        }

        private void yinpin_lujing_Load(object sender, EventArgs e)
        {
            DBHelper db = new DBHelper();
            db.OpenConnection();
            string sql = "select * from resource_path where resource_id=3";
            SqlCommand comm = new SqlCommand(sql, db.Connection);
            SqlDataReader reader = comm.ExecuteReader();
            while (reader.Read())
            {
                this.textBox1.Text = reader["resource_path"].ToString();
            }
            reader.Close();
            db.CloseConnection();
        }
    }
}
